﻿package org.xhs.report.common.model
{
    import flash.display.*;
    import flash.events.*;

    public class ScreenModel extends EventDispatcher
    {
        protected var _stage:Stage;
        protected var _stageHeight:Number;
        protected var _stageWidth:Number;
        protected var _displayState:String;
        protected var stageMask:Sprite;

        public function ScreenModel(param1:IEventDispatcher = null)
        {
            super(param1);
            return;
        }// end function

        public function set stage(param1:Stage) : void
        {
            this._stage = param1;
            this._stageWidth = this._stage.stageWidth;
            this._stageHeight = this._stage.stageHeight;
            this._displayState = this._stage.displayState;
            this._stage.addEventListener(Event.RESIZE, this.stageResizeHandler);
            this._stage.addEventListener(FullScreenEvent.FULL_SCREEN, this.fullScreenHandler);
            return;
        }// end function

        protected function stageResizeHandler(event:Event) : void
        {
            var _loc_2:Graphics = null;
            this._stageWidth = this._stage.stageWidth;
            this._stageHeight = this._stage.stageHeight;
            this._displayState = this._stage.displayState;
            if (this.stageMask)
            {
                this.stageMask.x = 0;
                this.stageMask.y = 0;
                _loc_2 = this.stageMask.graphics;
                _loc_2.clear();
                _loc_2.beginFill(16777215, 0.1);
                _loc_2.drawRect(0, 0, this._stageWidth, this._stageHeight);
                _loc_2.endFill();
            }
            dispatchEvent(event);
            return;
        }// end function

        protected function fullScreenHandler(event:FullScreenEvent) : void
        {
            this._displayState = event.fullScreen ? (StageDisplayState.FULL_SCREEN) : (StageDisplayState.NORMAL);
            dispatchEvent(event);
            return;
        }// end function

        public function get stageHeight() : Number
        {
            return this._stageHeight;
        }// end function

        public function get stageWidth() : Number
        {
            return this._stageWidth;
        }// end function

        public function get isFullscreen() : Boolean
        {
            return this._displayState == StageDisplayState.FULL_SCREEN;
        }// end function

        public function get stage() : Stage
        {
            return this._stage;
        }// end function

        public function set stageQulity(param1:String) : void
        {
            if (this._stage)
            {
                switch(param1)
                {
                    case StageQuality.BEST:
                    case StageQuality.HIGH:
                    case StageQuality.MEDIUM:
                    case StageQuality.LOW:
                    {
                        this._stage.quality = param1;
                        break;
                    }
                    default:
                    {
                        this._stage.quality = StageQuality.HIGH;
                        break;
                        break;
                    }
                }
            }
            return;
        }// end function

        public function addStageMask() : void
        {
            if (!this._stage)
            {
                return;
            }
            if (!this.stageMask)
            {
                this.stageMask = new Sprite();
            }
            var _loc_1:* = this.stageMask.graphics;
            _loc_1.clear();
            _loc_1.beginFill(16777215, 0.1);
            _loc_1.drawRect(0, 0, this._stageWidth, this._stageHeight);
            _loc_1.endFill();
            this._stage.addChild(this.stageMask);
            return;
        }// end function

        public function removeStageMask() : void
        {
            if (this.stageMask && this._stage && this._stage.contains(this.stageMask))
            {
                this._stage.removeChild(this.stageMask);
                this.stageMask = null;
            }
            return;
        }// end function

    }
}
